package com.shhm.common.dto.response;

import com.shhm.common.constants.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/7/22 下午3:03
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AjaxResultPlus extends HashMap<String, Object> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    // 状态码常量（可选）
    public static final String CODE_TAG = "code";
    public static final String MSG_TAG = "message";
    public static final String DATA_TAG = "data";
    public static final String IS_SHOW_MSG = "isShowMsg";

    /**
     * 创建成功响应
     */
    public static AjaxResultPlus success(boolean isShowMsg) {
        return new AjaxResultPlus().put(CODE_TAG, HttpStatus.SUCCESS).put(IS_SHOW_MSG,isShowMsg).put(MSG_TAG, "操作成功");
    }

    /**
     * 创建成功响应并添加数据
     */
    public static AjaxResultPlus success(Object data,boolean isShowMsg) {
        return new AjaxResultPlus().put(CODE_TAG, HttpStatus.SUCCESS).put(IS_SHOW_MSG,isShowMsg).put(MSG_TAG, "操作成功").put(DATA_TAG, data);
    }

    /**
     * 创建警告响应
     */
    public static AjaxResultPlus warn() {
        return new AjaxResultPlus().put(CODE_TAG, HttpStatus.WARN).put(MSG_TAG, "系统警告");
    }

    /**
     * 创建警告响应并添加提示
     */
    public static AjaxResultPlus warn(String message) {
        return new AjaxResultPlus().put(CODE_TAG, HttpStatus.WARN).put(MSG_TAG, message);
    }

    /**
     * 创建失败响应
     */
    public static AjaxResultPlus error() {
        return new AjaxResultPlus().put(CODE_TAG, HttpStatus.ERROR).put(MSG_TAG, "系统异常");
    }

    /**
     * 创建失败响应
     */
    public static AjaxResultPlus error(String msg) {
        return new AjaxResultPlus().put(CODE_TAG, HttpStatus.ERROR).put(MSG_TAG, msg);
    }
    /**
     * 创建失败响应
     */
    public static AjaxResultPlus error(int code,String msg) {
        return new AjaxResultPlus().put(CODE_TAG, code).put(MSG_TAG, msg);
    }

    /**
     * 创建自定义响应
     */
    public static AjaxResultPlus custom(int code,boolean isShowMsg) {
        return new AjaxResultPlus().put(CODE_TAG, code).put("isShowMsg", isShowMsg);
    }

    /**
     * 动态添加属性
     */
    public AjaxResultPlus put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
